<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>编辑项目收款-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<style>
	.w50{ width: 50px; }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
	<div id="main">
		<div class="crumbs">
			<div class="crumbs-text">项目款项列表 > 编辑项目收款</div>
		</div>
		<div id="content">
			<form action="__APP__/Financial/receivables_edit" method="post" id="project_add_form">
				<input type="hidden" name="action" value="edit">
				<input type="hidden" name="id" value="{$id}">
				<input type="hidden" name="keyword" value="{$keyword}">
				<input type="hidden" name="mode" value="{$mode}">
				<input type="hidden" name="center_id" value="{$center_id}">
				<input type="hidden" name="type" value="{$type}">
				<input type="hidden" name="ptype" value="{$ptype}">
				<input type="hidden" name="flag" id="flag">
				<div class="form-main">
					<div class="form-title">编辑项目收款</div>
					<div class="form-item">
						<div class="input-label">项目编号/名称</div>
						<div class="input-item">{$result['project_num']}/{$result['project_name']}</div>
					</div>
					<div class="form-item">
						<div class="input-label">合同金额</div>
						<div class="input-item ht_money">{$result['contract_money']}</div>
					</div>
					<div class="form-item">
						<div class="input-label">合同日期</div>
						<div class="input-item ht_date">{$result['contract_date']}</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>发票编号</div>
						<div class="input-item">
							<select name="tid" class="form-control w200 required_select" autocomplete="off">
								<option value="-10">请选择</option>
								<foreach name="detail" item="vo">
								<option value="{$vo['id']}" money_k="{$vo['money_k']-0}" money_y="{$vo['money_y']-0}" <if condition="$result_u['tid'] eq $vo['id']">selected</if>>{$vo['invoice']}</option>
								</foreach>
							</select>
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label">该发票编号开票金额</div>
						<div class="input-item money_1">{$result_u['money_y']-0}</div>
					</div>
					<div class="form-item">
						<div class="input-label">该发票编号已收款金额</div>
						<div class="input-item money_2">{$result_u['money_k']-0}</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>本次收款金额</div>
						<div class="input-item">
							<input type="text" class="form-control required_text w100" name="money" value="{$result_u['money']-0}" autocomplete="off">
							<span class="error-item">必填项</span>
							<span class="error-item">必须为正整数</span>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>本次收款日期</div>
						<div class="input-item">
							<input type="text" name="date" value="{$result_u['date']}" class="form-control Wdate w100 required_text" onClick="WdatePicker()" readonly autocomplete="off">
							<span class="error-item">必填项</span>
						</div>
					</div>
				</div>
				<div class="form-btn-item"><input type="submit" value="提交" class="btn btn-submit"><button class="btn btn-default goback" type="button">返回</button></div>
			</form>
		</div>
	</div>
</body>
<include file="Include:javascript" />
<script type="text/javascript">
	$(function() {
		/*编号联动*/
		$("[name='fid']").change(function(){
			var val = $(this).val();
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"fid":val,"action":"receivables"},
				url:"__APP__/Financial/project_funds_ajax",
				success:function(data){
					$('.ht_money').html(data.detail.contract_money);
					$('.ht_date').html(data.detail.contract_date);
					var html = "<option value='-10'>请选择</option>";
					for(var i=0;i<data.info.length;i++){
						html+= "<option value='"+data.info[i].id+"' money_k='"+data.info[i].money_k+"' money_y='"+data.info[i].money_y+"'>"+data.info[i].invoice+"</option>"
					}
					$("[name='tid']").html(html).select2();
				}
			})
		})
		/*发票联动*/
		$("[name='tid']").change(function(){
			var k = $(this).find("option:selected").attr("money_k"),
				y = $(this).find("option:selected").attr("money_y");
			$('.money_2').html(k);
			$('.money_1').html(y);
		})
		//收款金额验证
		$("[name='money']").change(function(){
			$("#flag").val(0);
			var money = $(this).val();
			var t=$("[name='tid']").val();
			if(money!='' && !/^[1-9]\d*$/.test(money)){
				$(this).nextAll('.error-item').eq(1).show();
			}

			$.ajax({
				type:"POST",
				asnyc:false,
				dataType:"json",
				data:{"money":money,"tid":t,"action":'edit'},
				url:"__APP__/Financial/check_get_money",
				success:function(data){
					if(data['status']==0){
						//flag隐藏值
						$("#flag").val(1);
						defeated_alert(data['msg']);
					}else{
						tag = true;
					}
				}
			});
		})
		/*表单验证*/
		$(".btn-submit").click(function(){
			var tag = false;
			
			$("[name='money']").each(function(){
				var val = $(this).val();
				if(val!='' && !/^[1-9]\d*$/.test(val)){
					$(this).nextAll('.error-item').eq(1).show();
					tag = true;
				}
			})
			$('.required_text').each(function(){
				var val = $(this).val();
				if(val==''){
					$(this).next('.error-item').show();
					tag = true;
				}
			})
			$('.required_select').each(function(){
				var val = $(this).val();
				if(val==-10){
					$(this).siblings('.error-item').show();
					tag = true;
				}
			})
			
			var flag = $("#flag").val();
			if(flag==1){
				defeated_alert('本次收款金额超限，请重新填写');
				tag = true;
			}
			
			if(tag){
				return false;
			}
		});

		/*取消错误提示*/
		$('.required_select').change(function(){
			$(this).siblings('.error-item').hide();
		})
		$('.required_text,.td_text').focus(function(){
			$(this).nextAll('.error-item').hide();
		})
	});
</script>
</html>